{extend name="public:base" /}
{block name="title"}后台管理-黑名单列表{/block}
{block name="body"}
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">日志管理</a>
        <a>
          <cite>黑名单列表</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
    </div>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5" method="get" action="{:url('admin/HomeAccess/black_lst')}">
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input"  autocomplete="off" placeholder="开始日" name="start" id="start">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input"  autocomplete="off" placeholder="截止日" name="end" id="end">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="ip"  placeholder="输入ip" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-header">
                        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
                        <button class="layui-btn" onclick="xadmin.open('添加黑名单','{:url('admin/HomeAccess/bw_add',array('type'=>0))}',600,400)"><i class="layui-icon"></i>添加黑名单</button>
                    </div>
                    <div class="layui-card-body ">
                      <table class="layui-table layui-form">
                        <thead>
                          <tr>
                            <th>
                              <input type="checkbox" lay-filter="checkall" name="" lay-skin="primary">
                            </th>
                            <th width="70">序号</th>
                            <th width="30">访问IP</th>
                            <th>详情</th>
                            <th>访问时间</th>
                            <th width="250">操作</th>
                        </thead>
                        <tbody class="x-cate">
                          {volist name="data" id="v" key="k"}
                            <tr class='delall_tr'>
                              <td>
                                <input type="checkbox" name="checkbox[]" value="{$v['id']}"  lay-skin="primary">
                              </td>
                              <td>{$k}</td>
                              <td>{$v['ip']}</td>
                              <td>{$v['desc']}</td>
                              <td>{$v['addtime']}</td>
                              <td class="td-manage">
                                  <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="member_del(this,'{$v['id']}')" href="javascript:;" >
                                    <i class="layui-icon">&#xe640;</i>删除
                                  </button>
                              </td>
                            </tr>
                          {/volist}
                        </tbody>
                      </table>
                    </div>
                    <div class="layui-card-body ">
                        <div class="page">
                            <div>
                              {$page}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div> 
{/block}

{block name="js"}
    <script>
      layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var form = layui.form;


         // 监听全选
        form.on('checkbox(checkall)', function(data){

          if(data.elem.checked){
            $('tbody input').prop('checked',true);
          }else{
            $('tbody input').prop('checked',false);
          }
          form.render('checkbox');
        }); 
        
        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });
      });


      /*用户-删除*/
      function member_del(obj,id){
          layer.confirm('确认要删除吗？',function(index){
              //发异步删除数据
              $.post("{:url('admin/HomeAccess/bw_del')}",{'id':id},function(e){
                if(e.code == 200){
                  $(obj).parents("tr").remove();
                  layer.msg('已删除!',{icon:1,time:1000});
                }else{
                  layer.msg(e.msg,{icon:2,time:1000});
                }
                return true;
              });
          });
      }

      function delAll (argument) {
        let id = '';
        let  checkbox = $('input[name="checkbox[]"]:checked');
        for (var i =  0; checkbox.length > i; i++) {
          if(id == ''){
            id += checkbox[i].value;
          }else{
            id += ','+checkbox[i].value;
          }
        }

        layer.confirm('确认要删除吗？',function(index){
            //捉到所有被选中的，发异步进行删除
            $.post("{:url('admin/HomeAccess/bw_del')}",{'id':id},function(e){
              if(e.code == 200){
                layer.msg('删除成功', {icon: 1});
                $(".layui-form-checked").not('.header').parents('tr').remove();
              }else{
                layer.msg(e.msg,{icon:2,time:1000});
              }
              return true;
            });
            
        });
      }

      function delAlls (argument) {

        layer.confirm('确认要清空访问列表吗？',function(index){
            //捉到所有被选中的，发异步进行删除
            $.post("{:url('admin/HomeAccess/delAll')}",{},function(e){
              if(e.code == 200){
                layer.msg('删除成功', {icon: 1});
                $(".delall_tr").remove();
              }else{
                layer.msg(e.msg,{icon:2,time:1000});
              }
              return true;
            });
            
        });
      }
    </script>
    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();</script>
{/block}